package com.fh.controller;



import com.fh.service.Demo2Service;
import com.utils.bean.*;
import com.utils.pulc.ResultBody;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author whf
 * @data 2023年 03月 24日
 */

@RestController
@RequestMapping("demo2")
@GlobalTransactional(rollbackFor = Exception.class)
public class Demo2Controller {

    @Autowired
    private Demo2Service demo2Service;

    /**
     * @description: 登录接口 如果密码正确则会登录并且查出他的信息
     * @author whf
     * @date 2023/5/10 14:21
     * @param safety
     * @return com.utils.pulc.ResultBody<com.utils.bean.User>
     */

    @PostMapping("index")
    public ResultBody<User> index(@Valid @RequestBody Safety safety){
        return ResultBody.ok(demo2Service.getSafety(safety));
    }

    /**
     * @description: 注册接口
     * @author whf
     * @date 2023/5/10 15:07
     * @param safetyAndUser
     */

    @PostMapping("setSafetyAndUser")
    public ResultBody<Object> setSafetyAndUser(@Valid @RequestBody SafetyAndUser safetyAndUser) {
        demo2Service.setSafetyAndUser(safetyAndUser);
        return ResultBody.ok();
    }

    /**
     * @description: 根据登录用户的id 查询权限
     * @author whf
     * @date 2023/4/25 15:03
     * @param substitute
     * @return com.fh.utils.ResultBody<java.lang.Object>
     */

    @PostMapping("selectAll")
    public ResultBody<List<Role>> selectAll(@RequestBody Substitute substitute) {
        return ResultBody.ok(demo2Service.selectUID(substitute));
    }

    /**
     * @description: 退出登录
     * @author whf
     * @date 2023/5/10 15:52
     * @param substitute
     * @return com.utils.pulc.ResultBody<java.lang.Object>
     */

    @PostMapping("exit")
    public ResultBody<String> exit(@RequestBody Substitute substitute){
      return ResultBody.ok(demo2Service.exitRedis(substitute));
    }
    /**
     * @description: 分页查询
     * @author whf
     * @date 2023/5/11 14:38
     * @param customerPage
     * @return com.utils.pulc.ResultBody<java.util.List<com.utils.bean.Customer>>
     */
    @PostMapping("page")
    public ResultBody<List<Customer>> getCustomerPage(@Valid @RequestBody CustomerPage customerPage){
        return ResultBody.ok(demo2Service.getCustomerPage(customerPage));
    }

    /**
     * @description: 对客户的信息进行添加
     * @author whf
     * @date 2023/5/11 14:36
     * @param customer
     * @return com.utils.pulc.ResultBody<java.lang.Object>
     */
    @PostMapping("save")
    public ResultBody<Object> save(@RequestBody Customer customer){
        demo2Service.save(customer);
        return ResultBody.ok();
    }


    /**
     * @description: 对他的ID进行删除
     * @author whf
     * @date 2023/5/17 9:20
     * @param
     * @return null
     */
    @PostMapping("delCostomer")
    public ResultBody<Object> delCostomer(@RequestBody CostomerID costomerID){
        demo2Service.delCustomer(costomerID);
        return ResultBody.ok();
    }
    /**
     * @description: 对一群人进行删除
     * @author whf
     * @date 2023/5/17 9:22
     * @param
     * @return com.utils.pulc.ResultBody<java.lang.Object>
     */
    @PostMapping("delCostomers")
    public ResultBody<Object> delCostomers(@RequestBody List<CostomerID> costomerIDS){
        demo2Service.delCustomers(costomerIDS);
        return ResultBody.ok();
    }

    /**
     * @description: 根据条件查询
     * @author whf
     * @date 2023/5/17 10:42
     * @param customer
     * @return com.utils.pulc.ResultBody<java.util.List<com.utils.bean.Customer>>
     */
    @PostMapping("getCustomerIF")
    public ResultBody<List<Customer>> getCustomerIF(@RequestBody Customer customer){
        return ResultBody.ok(demo2Service.getCustomerIF(customer));
    }

    /**
     * @description: 将图片保存在 static 文件下 然后把名字进行保存(数据库)
     * @author whf
     * @date 2023/5/31 8:50
     * @param multipartFileImag
     * @return com.utils.pulc.ResultBody<java.util.List<java.lang.String>>
     */
    @PostMapping( "setMultipartFile")
    public ResultBody<String> setMultipartFile(MultipartFileImag multipartFileImag){
        return ResultBody.ok(demo2Service.setMultipartFile(multipartFileImag));
    }

    /**
     * @description: 对保存的图片地址进行查询
     * @author whf
     * @date 2023/6/1 15:11
     * @param imagesOrUser
     * @return java.util.List<java.lang.String>
     */
    @PostMapping("getImage")
    public ResultBody<List<Photograph>> getImage(@RequestBody ImagesOrUser imagesOrUser){
        return ResultBody.ok(demo2Service.getImage(imagesOrUser));
    }

    /**
     * @param imagesUpdate
     * @return com.utils.pulc.ResultBody<java.lang.Object>
     * @description: 对图片进行删除
     * @author whf
     * @date 2023/6/1 17:23
     */
    @PostMapping("updateImages")
    public ResultBody<Object> updateImages(@RequestBody ImagesUpdate imagesUpdate){
        demo2Service.updateImages(imagesUpdate);
        return ResultBody.ok();
    }

    @PostMapping("updateMoney")
    public ResultBody<Object> updateMoney(@RequestBody MoneyAll money){
        demo2Service.updateMoney(money);
        return ResultBody.ok();
    }

}
